package threadcontrol;

import java.util.concurrent.CountDownLatch;

/**
 * 测试CountDownLatch类
 * @author lcx
 *- CountDownLatch不可重复使用,当计数器减少到0之后,就废了
 *  这个在程序设计中非常重要
 */
public class CountDownLatchTest {

	static int N=5;
	private static CountDownLatch latch=new CountDownLatch(N);

	public static void main(String[] args) {

		for(int i=0;i<3;i++)
		{
			Thread td=new Thread()
			{
				public void run()
				{
					System.out.println(Thread.currentThread().getName()+"  start....");
					System.out.println(Thread.currentThread().getName()+"  end....");
					latch.countDown();
				}
			};
			td.start();
		}
		try {
			latch.await();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
